package com.mojavelinux.open18;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;

import org.hibernate.validator.Range;

@Embeddable
public class USGARating implements Serializable {

	private static final long serialVersionUID = 1L;

	private Float course;

	private Float slope;

	public USGARating() {}
	
	public USGARating( Float course, Float slope ) {
		this.course = course;
		this.slope = slope;
	}
	
	@Column( name = "course_rating", precision = 0, scale = 0 )
	public Float getCourse() {
		return course;
	}

	public void setCourse( Float rating ) {
		this.course = rating;
	}

	@Column( name = "slope_rating", precision = 0, scale = 0 )
	@Range( min = 55, max = 155 )
	public Float getSlope() {
		return slope;
	}

	public void setSlope( Float slope ) {
		this.slope = slope;
	}
	
	/**
	 * This method is an artifact of JPA not allowing embedded objects
	 * to be null.  If the course and slope are both null, then
	 * it is assumed that a rating has not been assigned.
	 */
	@Transient
	public boolean isAssigned() {
		return ( course != null && slope != null);
	}
	
}
